//	Project:	HexTower
//	File:		GamePlayState.cpp
//	Author:		Mustafa Aldoori
//	Purpose:	Game Play State Implementation.

#include "GamePlayState.h"
#include "Direct3D_Manager.h"

CGamePlayState* CGamePlayState::GetInstance( void )
{
	static CGamePlayState s_Instance;

	return &s_Instance;
}

CGamePlayState::CGamePlayState( void )
{
	m_pC	= nullptr;
	m_pTM	= nullptr;
	m_nFrames		= 0;
	m_fFrameTimer	= 0;
	m_nFPS = 0;

	nBackgroundID = -1;
}

CGamePlayState::~CGamePlayState( void )
{

}

void CGamePlayState::Enter( void )
{
	m_pD3D			=	Direct3D_Manager::GetInstance();
	m_pDI			=	DirectInput_Manager::GetInstance();
	m_pGM			=	DirectGraphics_Manager::GetInstance();
	m_pC			=	CCursor::GetInstance();
	m_pHUD			=	CHUD::GetInstance();
	m_pTM			=	CTileManager::GetInstance();

	m_pHUD->Init();

	// Background Image
	nBackgroundID = m_pGM->LoadTexture( _T( "Resources/Graphics/Background.jpg" ) );

	// Cursor Image
	nCursorID = m_pGM->LoadTexture( _T("Resources/Graphics/GameCursor.png") );
	m_pC->SetCursorImage( nCursorID );

	m_fFrameTimer = 0;
	m_nFrames = 0;
}

void CGamePlayState::Exit( void )
{
	m_pD3D			= nullptr;
	m_pDI			= nullptr;
	m_pGM			= nullptr;
	m_pHUD			= nullptr;
	
	m_fFrameTimer = 0;
	m_nFrames = 0;
	m_nFPS = 0;
}

bool CGamePlayState::Input( void )
{
	if( m_pDI->KeyPressed( DIK_ESCAPE ) )
	{
		PostQuitMessage(0);
	}

	m_pHUD->Input();

	return true;
}

void CGamePlayState::Update( float fElapsed )
{
	m_pC->Update( fElapsed );

}

void CGamePlayState::Render( void )
{
	// Render Background
	m_pGM->Draw( nBackgroundID, 0, 0, 1.0f, 1.0f, nullptr, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB( 155, 255, 255, 255 ) ); 
	
	// Render HUD
	m_pHUD->Render();

	// Render Cursor Last
	m_pC->Render();
}